package cn.tedu.cinema.movie.controller;

import cn.tedu.cinema.base.response.JsonResult;
import cn.tedu.cinema.movie.pojo.dto.MovieQuery;
import cn.tedu.cinema.movie.pojo.dto.MovieSaveParam;
import cn.tedu.cinema.movie.pojo.vo.MovieVO;
import cn.tedu.cinema.movie.service.MovieService;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/v1/movie")
public class MovieController {
    @Autowired
    private MovieService movieService;

    @PostMapping("save")
    public JsonResult saveMovie( MovieSaveParam movieSaveParam) {
        log.debug("保存影片,参数={}", movieSaveParam);
        movieService.saveMovie(movieSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("delete/{id}")
    public JsonResult deleteMovie(@PathVariable("id") Long id) {
        log.debug("删除影片,参数={}", id);
        movieService.deleteMovieById(id);
        return JsonResult.ok();
    }

    @GetMapping("select")
    public JsonResult selectMovie(MovieQuery movieQuery) {
        log.debug("查询影片,参数={}", movieQuery);
        PageInfo<MovieVO> pageInfo = movieService.selectMovie(movieQuery);
        log.debug("查询结果:{}", pageInfo);
        return JsonResult.ok(pageInfo);
    }

    @GetMapping("selectById/{id}")
    public JsonResult selectMovieById(@PathVariable("id") Long id) {
        log.debug("查询影片,参数={}", id);
        MovieVO movieVO = movieService.selectMovieById(id);
        log.debug("查询结果:{}", movieVO);
        return JsonResult.ok(movieVO);
    }
}
